<%- content_for :title do -%>
  <%=h @task.title %>
<%- end -%>

<%- content_for :head do -%>
<%= stylesheet_link_tag 'tasks' %>
<%= stylesheet_link_tag 'protocalendar' %>
<% if editor? %>
  <%= javascript_include_tag 'prototype' %>
  <%= javascript_include_tag 'common' %>
  <%= javascript_include_tag 'protocalendar' %>
  <%= javascript_include_tag 'calendar' %>
  <%= javascript_include_tag 'tasks.show' %>
<% end %>
<%- end -%>

<div id="task-content">

  <% if editor? %><p class="toggle-edit"><a href="javascript:toggleEdit();void(0)"><img src='/images/edit.gif'/> 編集</a></p><% end %>

  <div id="show-task"<% if @editting %> style="display: none"<% end %>>
    <h2><%=h @task.title %></h2>
    <p class="span"><%=h @task.begin_at.strftime("%Y/%m/%d") %> - <%=h @task.end_at.strftime("%Y/%m/%d") %></p>
    <% unless @task.note.blank? %>
      <div class="note"><%= auto_link(simple_format(h(@task.note))) %></div>
    <% end %>
  </div>

  <% if editor? %>
    <div id="edit-task"<% unless @editting %> style="display: none"<% end %>>
    <% form_for(@task) do |f| %>
      <dl>
        <dt><%= f.label :title, 'タイトル' %></dt>
        <dd>
          <%= error_messages_on(:task, :title) %>
        </dd>
        <dd>
          <%= f.text_field :title, :size => 60 %>
  	  </dd>
  
  	  <dt><%= f.label :formatted_begin_at, '期間' %></dt>
        <dd>
          <%= error_messages_on(:task, :time) %>
          <%= error_messages_on(:task, :begin_at) %>
          <%= error_messages_on(:task, :end_at) %>
        </dd>
        <dd>
          <%= f.text_field :formatted_begin_at, :size => 15 %>
          から
          <%= f.text_field :formatted_end_at, :size => 15 %>
        </dd>
  	
        <dt><%= f.label :note, 'ノート' %></dt>
        <dd>
  	    <%= error_messages_on(:task, :note) %>
        </dd>
        <dd>
  	    <%= f.text_area :note, :cols => 60, :rows => 10 %>
  	  </dd>
        <p class="submit"><%= submit_tag '変更を保存' %></p>
      </dl>
    <% end %>
    </div>
  <% end %>

</div>

<div id="workers-content" class="list">
<%-
  begin_at = @task.begin_at
  end_at = @task.end_at
  if editor?
    begin_at -= 3.days
    end_at += 3.days
  end
-%>
<table>
  <thead>
  <tr>
    <th class="corner" rowspan="2"></th>
    <% each_month(begin_at, end_at) do |time| %>
      <th colspan="<%=h (([time.end_of_month, end_at].min - time) / 1.days).to_i + 1 %>">
        <%=h sprintf('%d年 %d月', time.year, time.month) %>
      </th>
    <% end %>
  </tr>
  <tr>
    <% each_days(begin_at, end_at) do |date| %>
      <th class="<%=h day_cell_classes(date, today).join(" ") %>"><% if date.day < 10 %><span style="visibility:hidden">0</span><% end %><%=h date.day %></th>
    <% end %>
  </tr>
  </thead>
  <tbody id="workers-body">
  <% @task.users.each do |user, periods| %>
    <tr id="worker-<%=h user.id %>" class="task task-<%=h cycle(1, 2) %>">
      <td class="name"><%=h user.name %></td>
      <% each_active_days(periods, begin_at, end_at) do |date, active| %>
        <td id="<%=h sprintf("cell-%d_%04d-%02d-%02d", user.id, date.year, date.month, date.day)%>"<% if active %> class="active"<% end %><% if editor? %> onmousedown="onDayCellMouseDown(event)" onmousemove="onDayCellMouseMove(event)" style="cursor: pointer"<% end %>></td>
      <% end %>
    </tr>
  <% end %>
  </tbody>
</table>


<% if editor? %>
  <p class="submit-worker">
    <% form_tag periods_task_path, :id => 'save-workers-form' do %>
      <%= submit_tag '変更を保存', :id => 'save-workers-submit', :disabled => flash[:workers_error].blank? %>
    <% end -%>
  </p>
</div>
<div id="add-worker-content">
  <% form_tag add_worker_task_path do -%>
    <p class="add-worker">
      <%= select_tag :name_select, options_for_select(@members.map(&:name) << '入力する...', params[:workers]) %>
      <%= text_field_tag :name, params[:worker], :style => 'display : none;' %>
      <%= submit_tag '担当者を追加' %>
    </p>
  <% end -%>
<% end %>

</div>

<% if editor? %>
  <p><%= link_to '削除する', @task, :confirm => 'タスクを削除してよろしいですか？', :method => :delete %></p>
<% end %>
